Imports System.IO
Imports System.Reflection

Namespace Framework

    ''' <summary>
    ''' Utility class for getting environment information.
    ''' </summary>
    Public NotInheritable Class EnvironmentHelper

        Private Const UnknownOS As String = "Unknown Win32 compatible OS"

        Private Sub New()
        End Sub

        Private Shared mAppPath As String = String.Empty
        Public Shared ReadOnly Property ApplicationPath() As String
            Get
                If mAppPath Is String.Empty Then
                    mAppPath = Path.GetDirectoryName(Application.ExecutablePath)
                End If
                Return mAppPath
            End Get
        End Property

        Public Shared Function GetOsName(ByVal os As OperatingSystem) As String
            Select Case os.Platform

                Case PlatformID.Win32Windows
                    If os.Version.Major = 4 Then
                        If os.Version.Minor = 0 Then Return "Windows 95"
                        If os.Version.Minor = 10 Then Return "Windows 98"
                        If os.Version.Minor = 90 Then Return "Windows ME"
                    End If
                    Return UnknownOS

                Case PlatformID.WinCE
                    Return "Windows CE"

                Case PlatformID.Win32NT
                    If (os.Version.Major = 3) Then Return "Windows NT 3.51"
                    If (os.Version.Major = 4) Then Return "Windows NT 4.0"
                    If (os.Version.Major = 6) Then Return "Windows codename Longhorn"
                    If (os.Version.Major = 5) Then
                        If (os.Version.Minor = 0) Then Return "Windows 2000"
                        If (os.Version.Minor = 1) Then Return "Windows XP"
                        If (os.Version.Minor = 2) Then Return "Windows 2003"
                    End If
                    Return UnknownOS

                Case Else
                    Return UnknownOS
            End Select
        End Function

        Public Shared Function GetOsNameWithVersion(ByVal os As OperatingSystem) As String
            Return String.Format("{0} {1}", GetOsName(os), os.Version.ToString())
        End Function

        Public Shared Function IsModernOS(ByVal os As OperatingSystem) As Boolean
            Return IIf((os.Platform = PlatformID.Win32NT) And (os.Version.Major > 4), True, False)
        End Function

    End Class
End Namespace
